import storage from '@/utils/storage'
import { isEmpty } from '@/utils/util'
import { APP_THEME } from '@/store/mutation-types'

const theme = {
  state: {
    // 当前自定义主题
    appTheme: {
      gradualBtn: 1,        //按钮颜色渐变
      mainBg: "#f59a63",    //主背景色
      mainBg2: "#E5915C",   //主背景色(渐变)
      mainFg: "#ffffff",    //主前景色
      viceBg: "#FFF9F5",    //副背景色
      viceBg2: "#fdf6ec",   //副背景色(渐变)
      viceFg: "#e4450d",    //副前景色
      mainText: "#342515",  //主文字颜色
      viceText: "#5B5A5A",  //副文字颜色
      pageBg: "#f1f3f6",    //页面背景色
      matchColor: "#fca336",//配色
    },
  },

  mutations: {
    SET_APP_THEME: (state, value) => {
      if (!isEmpty(value)) {
        state.appTheme = value
      }
    }
  },

  actions: {

    // 记录自定义主题
    SetAppTheme({ commit }, value) {
      return new Promise((resolve, reject) => {
        storage.set(APP_THEME, value)
        commit('SET_APP_THEME', value)
        resolve()
      })
    }

  }
}

export default theme
